{% extends "base.html" %}

{% block content %}
<div class="row justify-content-center">
    <div class="col-md-8">
        <div class="card">
            <div class="card-header">
                <h4>
                    {% if is_edit %}
                        编辑文章
                    {% else %}
                        发布新文章
                    {% endif %}
                </h4>
            </div>
            <div class="card-body">
                <form method="POST">
                    <div class="mb-3">
                        <label for="title" class="form-label">文章标题</label>
                        <input type="text" class="form-control" id="title" name="title"
                               value="{{ post.title if post else '' }}" required>
                    </div>
                    <div class="mb-3">
                        <label for="content" class="form-label">文章内容</label>
                        <textarea class="form-control" id="content" name="content" rows="10" required>{{ post.content if post else '' }}</textarea>
                    </div>
                    <div class="d-flex gap-2">
                        <button type="submit" class="btn btn-primary">
                            {% if is_edit %}
                                更新文章
                            {% else %}
                                发布文章
                            {% endif %}
                        </button>
                        <a href="{{ url_for('index') }}" class="btn btn-secondary">取消</a>

                        {% if is_edit %}
                        <a href="{{ url_for('delete_post', post_id=post.id) }}" class="btn btn-danger ms-auto"
                           onclick="return confirm('确定要删除这篇文章吗？此操作不可撤销。')">
                            删除文章
                        </a>
                        {% endif %}
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{% endblock %}